﻿/*****************************************************
**Copyright(C), 2021-2022, Ciqtek Technology.
**Version:     2.0
**Author:      hujiarui
**Date:        2023/06/28
**Description: BaseGraphicsItem管理基类
*****************************************************/

#ifndef BASEITEMMANAGER_H
#define BASEITEMMANAGER_H

#include "../../ofuidll_global.h"

#include <QObject>
#include <QGraphicsScene>
#include <QCursor>

namespace OfUI {

	class BaseGraphicsItem;
	class OFUIDLL_EXPORT BaseItemManager : public QObject
	{
		Q_OBJECT

	public:
		/**
		 * @brief  BaseItemManager 构造函数
		 * @param  pScene
		 * @param  parent
		 * @return
		 */
		BaseItemManager(QGraphicsScene* pScene, QObject *parent);

		/**
		 * @brief  ~BaseItemManager 析构函数
		 * @return
		 */
		virtual ~BaseItemManager();

	public:
		/**
		 * @brief  setAddType 设置添加Item类型
		 * @param  nType
		 * @return void
		 */
		virtual void setAddType(int nType);

		/**
		 * @brief  setSelected 设置为当前选中Item
		 * @param  pItem
		 * @return void
		 */
		virtual void setSelected(BaseGraphicsItem* pItem);

		/**
		 * @brief  clearSelected 清除当前Item选中状态
		 * @return void
		 */
		virtual void clearSelected();

		/**
		 * @brief  removeItem 删除Item
		 * @param  pItem
		 * @return void
		 */
		virtual void removeItem(BaseGraphicsItem* pItem);

		/**
		 * @brief  removeAll 删除全部Item
		 * @return void
		 */
		virtual void removeAll();

	public:
		/**
		 * @brief  mousePressEvent 鼠标按下事件（Scene透传）
		 * @param  event
		 * @return void
		 */
		virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);

		/**
		 * @brief  mouseReleaseEvent 鼠标弹起事件（Scene透传）
		 * @param  event
		 * @return void
		 */
		virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);

		/**
		 * @brief  mouseMoveEvent 鼠标移动事件（Scene透传）
		 * @param  event
		 * @return void
		 */
		virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);

		/**
		 * @brief  mouseDoubleClickEvent 鼠标双击事件（Scene透传）
		 * @param  event
		 * @return void
		 */
		virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);

		/**
		 * @brief  focusOutEvent 失焦事件（Scene透传）
		 * @param  event
		 * @return void
		 */
		virtual void focusOutEvent(QFocusEvent *event);

	protected:
		/**
		 * @brief  select 判断坐标点是否选中Item
		 * @param  point
		 * @return BaseGraphicsItem*
		 */
		virtual BaseGraphicsItem* select(const QPointF& point) = 0;

		/**
		 * @brief  createItem 创建Item
		 * @return BaseGraphicsItem*
		 */
		virtual BaseGraphicsItem* createItem() = 0;

		/**
		 * @brief  createCursor 创建Item光标
		 * @return QCursor
		 */
		virtual QCursor createCursor() const;

	protected:
		/** 当前创建Item类型
		 */
		int m_nAddType;

		/** 场景
		 */
		QGraphicsScene* m_pScene;

		/** 管理的Item列表
		 */
		QList<BaseGraphicsItem*> m_itemList;

		/** 当前选中Item
		 */
		BaseGraphicsItem* m_pSelectItem;
	};
}

#endif // BASEITEMMANAGER_H
